var app = angular.module("myApp", ["ngRoute", "ngCookies"]);

app.controller("mainAll", function($scope, $rootScope, $http, $location, $anchorScroll, $route, $cookieStore) {
	$rootScope.setCookie = function(obj) {
		$cookieStore.put('classType', obj);
		$rootScope.Cookie = $cookieStore.get('classType');
		$cookieStore.remove('classType');
	}
	var css = document.getElementById("CSS");
	css.href = "css/main.css";
	var URL = $location.path() ? $location.path() : "/main";
	if(URL == "/" || "") {
		URL = "/main";
	} else {
		URL = $location.path();
	}
	css.href = "css" + URL + ".css";
	$http({
		method: "GET",
		url: "php/index.php"
	}).then(function(response) {
		$rootScope.imgArray = response.data;
	});
	//	锚点操作，需引进 $anchorScroll 参数
	//	锚点操作----angularJS中锚点与路由操作有冲突，解决方法
	$scope.goto = function(id) {
		$anchorScroll(id);
	}
	$scope.collect = function() {
		alert("加入收藏失败，请使用Ctrl+D进行添加");
	}
});
app.config(["$locationProvider", function($locationProvider) {
	$locationProvider.hashPrefix("");
}]);
app.config(function($routeProvider) {
	$routeProvider.when('/', {
		templateUrl: "main.html",
		controller: "mainAll"
	});
	$routeProvider.when('/main', {
		templateUrl: "main.html",
		controller: "mainAll"
	});
	$routeProvider.when("/shopcity", {
		templateUrl: "shopcity.html",
		controller: "mainAll"
	});
	$routeProvider.when("/floor", {
		templateUrl: "floor.html",
		controller: "mainAll"
	});
	$routeProvider.when("/Merchants", {
		templateUrl: "Merchants.html",
		controller: "mainAll"
	});
	$routeProvider.when("/connect", {
		templateUrl: "connect.html",
		controller: "mainAll"
	});
	$routeProvider.when('/ListInfo', {
		templateUrl: "ListInfo.html",
		controller: "mainAll"
	});
	$routeProvider.otherwise({
		templateUrl: "main.html",
		controller: "mainAll"
	});
});